package com.macro.mall.service.impl;

import com.github.xiaoymin.swaggerbootstrapui.util.CommonUtils;
import com.macro.mall.mapper.CommonMapper;
import com.macro.mall.mapper.UmsMemberGroupsMapper;
import com.macro.mall.model.UmsMember;
import com.macro.mall.model.UmsMemberGroups;
import com.macro.mall.service.CommonService;
import com.macro.mall.service.UmsMemberGroupService;
import java.util.List;
import java.util.Map;

import com.macro.mall.utils.Mapping;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UmsMemberGroupServiceImpl implements UmsMemberGroupService {
    private static final Logger log = LoggerFactory.getLogger(UmsMemberGroupServiceImpl.class);

    @Autowired
    UmsMemberGroupsMapper umsMemberGroupsMapper;

    public List<Map> findCommunity(String countyCode) {
        return this.umsMemberGroupsMapper.findCommunity(countyCode);
    }

    public List<Map> findGroups(Long communityId) {
        return this.umsMemberGroupsMapper.findGroups(communityId);
    }

    public List<Map> findMembers(Long communityId, String groupId) {
        return this.umsMemberGroupsMapper.findMembers(communityId, groupId);
    }

    public void saveMemberGroups(UmsMember build, String userIdentity) {
        for(String groupId:userIdentity.split(",")){
            Integer nums = umsMemberGroupsMapper.countGroups(build.getId(),groupId);
            if(nums>0){
                continue;
            }
            UmsMemberGroups groups = new UmsMemberGroups();
            groups.setMemberId(build.getId());
            groups.setName(build.getName());
            groups.setPhone(build.getPhone());
            groups.setCommunityId(build.getCommunityId());
            groups.setCommunityName(build.getCommunityName());
            groups.setGroupId(groupId);
            groups.setGroupName(Mapping.userIdentityMap.get(groupId));
            umsMemberGroupsMapper.insert(groups);
        }
    }
}
